﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class Prop_description_Frame : MonoBehaviour
{
    public static Prop_description_Frame _instance;
    public Text Des_Type;// 标明这是个什么类型的道具
    public Text Des_Text;// 具体的描述内容
    public float timer = 0;//计时器 

    private void Awake()
    {
        _instance = this;
    }
    // Start is called before the first frame update
    void Start()
    {
        Des_Type = transform.Find("Des_Type").GetComponent<Text>();
        Des_Text = transform.Find("Des_Text").GetComponent<Text>();
    }

    // Update is called once per frame
    void Update()
    {

        if(this.gameObject.activeInHierarchy == true)
        {
            timer -= Time.deltaTime;
            if(timer < 0)
            {
                this.gameObject.SetActive(false);
            }
        }
    }
    // 道具描述的语言
    public void Describe_Prop_By_Id(int id)
    {
        Objectinfo info = ObjectsInfo._instance.getObjectinfobyid(id);
        Describe_Prop(info);
    }

    public void Describe_Prop(Objectinfo info)
    {
        this.gameObject.SetActive(true);
        timer = 0.1f;
        transform.position = Input.mousePosition;

        string description;
        switch (info.str_type)
        {
            case Objecttype.drug:
                Des_Type.text = info.name + " ";
                description = Describe_Drug(info);
                break;
            case Objecttype.equipment:
                Des_Type.text = info.name + " ";
                description = Describe_Weapon(info);
                break;
            case Objecttype.material:
                Des_Type.text = info.name + " ";
                description = Describe_Material(info);
                break;
            default:
                description = "异常道具类型";
                break;
        }

        Des_Text.text = description;
        this.GetComponent<RectTransform>().SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, Des_Type.preferredHeight + Des_Text.preferredHeight + 20);
    }

    public string Describe_Drug(Objectinfo info)
    {
        string str = "";
        str += info.describe + "\n";
        str += "类型：回复道具\n";
        if (info.hp != 0) str += "血量：+" + info.hp.ToString() + "\n";
        if (info.radiation != 0) str += "辐射度：" + info.radiation.ToString() + "\n";
        if (info.food != 0) str += "饱食度：" + info.food.ToString() + "\n";
        if (info.water != 0) str += "饱水度：" + info.water.ToString() + "\n";
        if (info.cause_buffID != 0) str += BuffInfo._instance.getBuffInfobyid(info.cause_buffID).tag + "\n";
        if (info.defuse_buffID != 0) str +="失去" + BuffInfo._instance.getBuffInfobyid(info.defuse_buffID).tag + "\n";

        str += "重量：" + info.weight;

        return str;
    }
    public string Describe_Material(Objectinfo info)
    {
        string str = "";
        str += "类型：材料\n";
        str += info.describe + "\n";
        str += "重量：" + info.weight;
        return str;
    }
    public string Describe_Weapon(Objectinfo info)
    {
        string str = "";
        str += info.describe + "\n";

        str += "类型：装备\n";
        str += "具体类型：";
        switch (info.equip_Type)
        {
            case Equip_type.Armor:
                str += "护甲";
                break;
            case Equip_type.Headgear:
                str += "头盔";
                break;
            case Equip_type.Shoes:
                str += "鞋具";
                break;
            case Equip_type.Weapon:
                str += "主武器";
                break;
            case Equip_type.Sub_Weapon:
                str += "副武器";
                break;
            case Equip_type.Hands:
                str += "护腕";
                break;
        }

        str += "\n";
        if(info.damage != 0)  str += "攻击力：" + info.damage + "\n";
        if (info.coldtime != 0) str += "冷却时间：" + info.coldtime + "\n";
        // 有关弹药的先不管
        if (info.armor != 0) str += "护甲：" + info.armor + "\n";
        if (info.anti_rad != 0) str += "辐射抗性";
        str += "重量：" + info.weight;

        return str;
    }
}
